package com.lute.report;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.jasperreports.engine.JRDataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.common.json.JSONArray;
import org.springframework.security.oauth2.common.json.JSONException;
import org.springframework.security.oauth2.common.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.lute.model.User;
import com.lute.model.UserAccountState;
import com.lute.model.UserEntitlement;
import com.lute.utils.ServerErrorResponse;

@Controller
public class LuteMonthlySummaryReportServlet {
	
	@RequestMapping(value = "/monthlyReport", method = RequestMethod.GET)
	public ModelAndView luteSummaryReport(ModelAndView modelAndView,HttpServletRequest request) {
	 
	LuteMonthlySummaryReport dataprovider = new LuteMonthlySummaryReport();
	List<Integer> employeeIds = new ArrayList<Integer>();
	List<String> calFroms = new ArrayList<String>();
	
	HttpSession session = request.getSession();
	String reportFormat = (String)session.getAttribute("format");
	employeeIds = (ArrayList<Integer>)session.getAttribute("employees");
	calFroms = (ArrayList<String>)session.getAttribute("froms");
//	employeeIds.add(4);
//	employeeIds.add(8);
//	calFroms.add("2013-02-01");
	
	JRDataSource datasource  = dataprovider.getDataSource(employeeIds, calFroms);

	Map<String,Object> parameterMap = new HashMap<String,Object>();
	parameterMap.put("datasource", datasource);
	
	modelAndView = new ModelAndView(reportFormat+"MonthlyReport", parameterMap);
	 
	return modelAndView;
	}
}
